<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="author" content="史帅超">
        <title>Map Set</title>
        <script>
            
        </script>
    </head>
    <body>
        
        <script>
// Map

            var m = new Map([['小明',95],['xiaohong',85],['xiaoli',90]]);
            // 取到某个键的值
            var num = m.get('xiaoli');
            // 放进去某个键值对
            m.set('xiaowang',100);
            console.log(num);//90
            console.log(m.get('xiaowang'));//100
            console.log(m);//多了个xiaowang:100

            m.delete('小明');
            console.log(m);//少了个 小明：95

            m.set("xiaoshi",101);
            m.set("xiaoshi",103);
            console.log(m.get("xiaoshi"));//103

    // 此为矩阵，跟map有区别
            var array1 = [[1,2,3],[4,5,6],[7,8,9]] ;
            console.log(array1[1][1]);//取到5
        // 遍历该矩阵
            var arr3='';
            for(i=0;i<3;i++){
                for(j=0;j<3;j++){
                    var arr2 = array1[i][j];
                    console.log(arr2);//123456789(Number类型）
                    arr3 = arr3+arr2;
                }
            }
            console.log(arr3);//123456789(string类型)
            
    
// Set
            // set,跟map一样也是一组key的集合，但set中不存储value
            //set中会自动过滤掉重复的元素
            var s = new Set([1,2,3,3,'3']);
            console.log(s); //   Set[1,2,3,'3']

            // 添加
            s.add(4);
            console.log(s);
            s.add('nihao');
            console.log(s);

            // 删除
            s.delete(1);
            console.log(s);
            s.delete('nihao');
            console.log(s);
        </script>
    </body>
</html>